# Copyright (c) 2024 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache Software License 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
# which is available at https://opensource.org/licenses/MIT.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT

workspace(name = "org_eclipse_iceoryx_iceoryx2")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")

# Setup gtest
GOOGLETEST_VERSION = "1.14.0"
maybe(
    name = "googletest",
    repo_rule = http_archive,
    urls = ["https://github.com/google/googletest/archive/refs/tags/v{version}.zip".format(version = GOOGLETEST_VERSION)],
    sha256 = "1f357c27ca988c3f7c6b4bf68a9395005ac6761f034046e9dde0896e3aba00e4",
    strip_prefix = "googletest-{version}".format(version = GOOGLETEST_VERSION),
)


# Load Rust rules
# Use v0.26 to support bazel v6.2
maybe(
    name = "rules_rust",
    repo_rule = http_archive,
    sha256 = "9d04e658878d23f4b00163a72da3db03ddb451273eb347df7d7c50838d698f49",
    urls = ["https://github.com/bazelbuild/rules_rust/releases/download/0.26.0/rules_rust-v0.26.0.tar.gz"],
)

load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains")

rules_rust_dependencies()
rust_register_toolchains(
    edition = "2021",
    versions = [
        "1.80.0"
    ],
)


# Load prebuilt bindgen
maybe(
    name = "bindgen",
    repo_rule = http_archive,
    sha256 = "b7e2321ee8c617f14ccc5b9f39b3a804db173ee217e924ad93ed16af6bc62b1d",
    strip_prefix = "bindgen-cli-x86_64-unknown-linux-gnu",
    urls = ["https://github.com/rust-lang/rust-bindgen/releases/download/v0.69.5/bindgen-cli-x86_64-unknown-linux-gnu.tar.xz"],
    build_file_content = """
filegroup(
    name = "bindgen-cli",
    srcs = ["bindgen"],
    visibility = ["//visibility:public"],
)
    """,
)

# Load prebuilt cbindgen
maybe(
    name = "cbindgen",
    repo_rule = http_file,
    sha256 = "521836d00863cb129283054e5090eb17563614e6328b7a1610e30949a05feaea",
    urls = ["https://github.com/mozilla/cbindgen/releases/download/0.26.0/cbindgen"],
    executable = True,
)

# Load external crates
load("@rules_rust//crate_universe:repositories.bzl", "crate_universe_dependencies")

crate_universe_dependencies()

load("@rules_rust//crate_universe:defs.bzl", "crates_repository")

maybe(
    name = "crate_index",
    repo_rule = crates_repository,
    cargo_lockfile = "//:Cargo.lock",
    lockfile = "//:Cargo.Bazel.lock",
    manifests = [
        "//:Cargo.toml",
        "//:benchmarks/event/Cargo.toml",
        "//:benchmarks/publish-subscribe/Cargo.toml",
        "//:benchmarks/queue/Cargo.toml",
        "//:examples/Cargo.toml",
        "//:iceoryx2/Cargo.toml",
        "//:iceoryx2-bb/container/Cargo.toml",
        "//:iceoryx2-bb/derive-macros/Cargo.toml",
        "//:iceoryx2-bb/elementary/Cargo.toml",
        "//:iceoryx2-bb/lock-free/Cargo.toml",
        "//:iceoryx2-bb/log/Cargo.toml",
        "//:iceoryx2-bb/memory/Cargo.toml",
        "//:iceoryx2-bb/posix/Cargo.toml",
        "//:iceoryx2-bb/system-types/Cargo.toml",
        "//:iceoryx2-bb/testing/Cargo.toml",
        "//:iceoryx2-bb/threadsafe/Cargo.toml",
        "//:iceoryx2-bb/trait-tests/Cargo.toml",
        "//:iceoryx2-cal/Cargo.toml",
        "//:iceoryx2-cli/Cargo.toml",
        "//:iceoryx2-ffi/ffi-macros/Cargo.toml",
        "//:iceoryx2-ffi/ffi/Cargo.toml",
        "//:iceoryx2-pal/concurrency-sync/Cargo.toml",
        "//:iceoryx2-pal/configuration/Cargo.toml",
        "//:iceoryx2-pal/posix/Cargo.toml",
    ],
)

load("@crate_index//:defs.bzl", "crate_repositories")

crate_repositories()

BAZEL_SKYLIB_VERSION = "1.7.1"

# Load skylib for custom build config
maybe(
    name = "bazel_skylib",
    repo_rule = http_archive,
    sha256 = "bc283cdfcd526a52c3201279cda4bc298652efa898b10b4db0837dc51652756f",
    urls = [
        "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/{version}/bazel-skylib-{version}.tar.gz".format(version = BAZEL_SKYLIB_VERSION),
        "https://github.com/bazelbuild/bazel-skylib/releases/download/{version}/bazel-skylib-{version}.tar.gz".format(version = BAZEL_SKYLIB_VERSION),
    ],
)

load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()


# Load iceoryx rules
ICEORYX_VERSION = "2.95.3"

maybe(
    name = "iceoryx",
    repo_rule = http_archive,
    sha256 = "14b854906b58a48140a5d074167d5f3a5af2d578574940501a330954af79b9d4",
    strip_prefix = "iceoryx-{}".format(ICEORYX_VERSION),
    url = "https://github.com/eclipse-iceoryx/iceoryx/archive/v{}.tar.gz".format(ICEORYX_VERSION),
)

# Load iceoryx dependencies
load("@iceoryx//bazel:load_repositories.bzl", "load_repositories")

load_repositories()

# Setup iceoryx dependencies
load("@iceoryx//bazel:setup_repositories.bzl", "setup_repositories")

setup_repositories()
